package Models;

import java.rmi.RemoteException;
import java.util.LinkedList;

import listeners.CanPieceCaptureListener;
import listeners.CanMoveListenerPiece;

public class KnightModel implements ChessPieceModel {

	private boolean canJump = true;
	private Player player;
	private boolean hasMove;
	private LinkedList<CanMoveListenerPiece> canPieceMoveListeners = new LinkedList<CanMoveListenerPiece>();
	private LinkedList<CanPieceCaptureListener> canPieceCaputureListeners = new LinkedList<CanPieceCaptureListener>();
	
public KnightModel(Player player) {
	hasMove = false;
	this.player = player;
}

@Override	
public void setMove(boolean hasMove) {
	this.hasMove = hasMove;
}

@Override
public boolean getMove() {
	return hasMove;
}

@Override
public void addCanPieceMoveListener(CanMoveListenerPiece listener) {
	canPieceMoveListeners.add(listener);
}

@Override
public void removeCanPieceMoveListener(CanMoveListenerPiece listener) {
	canPieceMoveListeners.remove(listener);
}

@Override
public boolean canPieceMoveNotify(Point2D from, Point2D to)
		throws RemoteException {
	
	for(CanMoveListenerPiece listener : canPieceMoveListeners)
	{
		if(!listener.canPieceMoveNotify(from, to, this))
			return false;
	}
		
	return true;
}

@Override
public boolean canJump() {
	
	
	return canJump;
}

@Override
public void addCanPieceCaptureListener(CanPieceCaptureListener listener) {
	canPieceCaputureListeners.add(listener);
	
}

@Override
public void removeCanPieceCaptureListener(CanPieceCaptureListener listener) {
	canPieceCaputureListeners.remove(listener);
	
}

@Override
public boolean canPieceCaptureNotify(Point2D from, Point2D to)
		throws RemoteException {
	for(CanPieceCaptureListener listener : canPieceCaputureListeners)
	{
		if(!listener.CanPieceCaptureNotify(from, to, this))
			return false;
	}
		
	return true;
}

@Override
public Player getPlayer() {
	
	return player;
}





}
